﻿using System.Collections;
using System.ComponentModel;
using System.Configuration.Install;
using System.ServiceProcess;

namespace X18.Gather.GatherService
{
    [RunInstaller(true)]
    public partial class ServicesInstaller : Installer
    {
        private ServiceProcessInstaller processInstaller;
        private ServiceInstaller serviceInstaller;

        public ServicesInstaller()
        {
            this.processInstaller = new ServiceProcessInstaller();
            this.serviceInstaller = new ServiceInstaller();
            this.serviceInstaller.StartType = ServiceStartMode.Automatic;
            this.serviceInstaller.ServiceName = "X18.Gather.GatherService";
            this.serviceInstaller.Description = "X8数据采集服务";
            this.processInstaller.Account = ServiceAccount.LocalSystem;
            base.Installers.Add(this.serviceInstaller);
            base.Installers.Add(this.processInstaller);
        }

        public override void Install(IDictionary stateSaver)
        {
            if (base.Context != null && base.Context.Parameters != null)
            {
                string user = base.Context.Parameters["user"];
                string password = base.Context.Parameters["password"];
                if (!string.IsNullOrEmpty(user))
                {
                    this.processInstaller.Account = ServiceAccount.User;
                    this.processInstaller.Username = user;
                    this.processInstaller.Password = password;
                }
            }
            base.Install(stateSaver);
        }

        public string RequiredGroups
        {
            get
            {
                return "Administrators";
            }
        }
    }
}
